import common from '/@/common/common'
// @ts-ignore
const client = window.client

interface BaseType{
  telnet(host: string, port?: number): Promise<string>
}

class NetTest implements BaseType{
  async telnet(host: string, port?: number): Promise<string> {
    if(common.objectUnavailable(port)){
      port = 80
    }
    let result = ""
    try {
      result =  await client.ping(host, port)
      if(result){
        return 'connect sucess'
      } else {
        return 'connect fail'+result.toString()
      }
    } catch(e){
      return (e as Error).message
    }
    // .then(() => console.log('connect ping sucess '+host+':'+port))
    // .catch((e: any) => console.error('not disconnet', e))
  }
}

const netTest = new NetTest()
export default netTest


